<template>
  <el-row :gutter="24">
    <el-col :span="10">
      <el-card v-loading="loadingVerifyDiv">
        <div slot="header" class="clearfix">
          <span>结算日期修复</span>
        </div>
        <el-form :model="criteriaForm" ref="basisForm" size="mini" label-width="100px">
          <el-form-item label="海空运运单号" prop="seaairWaybillNos">
            <el-input v-model="criteriaForm.seaairWaybillNos" type="textarea" placeholder="多个换行"
                      :autosize="{minRows: 4, maxRows: 4}" :style="{width: '100%'}"></el-input>
          </el-form-item>
          <el-form-item label="海外仓运单号" prop="abroadWaybillNos">
            <el-input v-model="criteriaForm.abroadWaybillNos" type="textarea" placeholder="多个换行"
                      :autosize="{minRows: 4, maxRows: 4}" :style="{width: '100%'}"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="fixAmoebaSettlementCenterCostDate">修复</el-button>
          </el-form-item>
        </el-form>
      </el-card>
    </el-col>

    <el-col :span="14">
      <el-card v-loading="loadingVerifyDiv2">
        <div slot="header" class="clearfix">
          <span>修改所属部门(单号、结算日期至少选择录入一个)</span>
        </div>
        <el-form ref="elForm" :model="criteriaForm2" :rules="channgeDepartRules" size="mini" label-width="135px">
          <el-form-item label="海空运运单号" prop="seaairWaybillNos">
            <el-input v-model="criteriaForm2.seaairWaybillNos" type="textarea" placeholder="多个换行"
                      :autosize="{minRows: 4, maxRows: 4}" :style="{width: '100%'}"></el-input>
          </el-form-item>
          <el-form-item label="海外仓运单号" prop="abroadWaybillNos">
            <el-input v-model="criteriaForm2.abroadWaybillNos" type="textarea" placeholder="多个换行"
                      :autosize="{minRows: 4, maxRows: 4}" :style="{width: '100%'}"></el-input>
          </el-form-item>
          <el-form-item label="阿米巴科目" prop="amoebaSubjectId">
            <el-select v-model="criteriaForm2.amoebaSubjectId" placeholder="请选择阿米巴科目" clearable
                       :style="{width: '100%'}">
              <el-option v-for="(item, value) in amoebaSubjectMap" :key="value" :label="item" :value="value"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="结算日期(开始)" prop="field104">
            <el-date-picker v-model="criteriaForm2.startCostDate" format="yyyy-MM-dd" value-format="yyyy-MM-dd"
                            :style="{width: '100%'}" placeholder="请选择开始日期" clearable></el-date-picker>
          </el-form-item>
          <el-form-item label="结算日期(结束)" prop="field105">
            <el-date-picker v-model="criteriaForm2.endCostDate" format="yyyy-MM-dd" value-format="yyyy-MM-dd"
                            :style="{width: '100%'}" placeholder="请选择结束日期" clearable></el-date-picker>
          </el-form-item>
          <el-form-item label="结算人" prop="settleManId">
            <el-select v-model="criteriaForm2.settleManId" placeholder="请选择结算人" clearable filterable
                       :style="{width: '100%'}">
              <el-option v-for="(item, value) in userMap" :key="value" :label="item" :value="value"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="目前所属部门" prop="belongDepartId">
            <el-select v-model="criteriaForm2.belongDepartId" placeholder="请选择所属部门" clearable filterable
                       :style="{width: '100%'}">
              <el-option v-for="(item, value) in userDepartMap" :key="value" :label="item" :value="value"></el-option>
            </el-select>
          </el-form-item>

          <el-divider></el-divider>

          <el-form-item label="修改后的所属部门" prop="updateBelongDepartId">
            <el-select v-model="criteriaForm2.updateBelongDepartId" placeholder="请选择修改后的所属部门" clearable filterable
                       :style="{width: '100%'}">
              <el-option v-for="(item, value) in userDepartMap" :key="value" :label="item" :value="value"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="fixAmoebaSettlementCenterBelongDepartCommit">提交</el-button>
          </el-form-item>
        </el-form>
      </el-card>

    </el-col>

  </el-row>



</template>

<script>
  import {ajax} from "@/store/yg/common/utils";
  export default {
    data() {
      return {
        loadingVerifyDiv:false,
        loadingVerifyDiv2: false,
        userMap:{},
        amoebaSubjectMap:{},
        userDepartMap:{},
        criteriaForm2:{
          seaairWaybillNos: null,
          abroadWaybillNos: null,
          startCostDate: null,
          endCostDate: null,
          settleManId: null,
          belongDepartId: null,
          updateBelongDepartId: null,
          amoebaSubjectId: null
        },
        criteriaForm: {
          seaairWaybillNos: null,
          abroadWaybillNos: null
        },
        channgeDepartRules: {
          settleManId: [{
            required: true,
            message: '请选择结算人',
            trigger: 'change'
          }],
          belongDepartId: [{
            required: true,
            message: '请选择所属部门',
            trigger: 'change'
          }],
          updateBelongDepartId: [{
            required: true,
            message: '请选择修改后的所属部门',
            trigger: 'change'
          }],
        }
      }
    },
    created() {
      this.initSelector();
    },
    methods: {
      async initSelector(){
        // console.log(this.$store.state.blank.entry.sources);
        this.userMap = this.$store.state.blank.entry.sources["userSource"];
        this.amoebaSubjectMap = this.$store.state.blank.entry.sources["amoebaSubjectSource"];
        this.userDepartMap = this.$store.state.blank.entry.sources["userDeparSource"];
      },
      fixAmoebaSettlementCenterBelongDepartCommit(){
        this.$refs['elForm'].validate(valid => {
          if (!valid) return

          this.fixAmoebaSettlementCenterBelongDepart(this.criteriaForm2);
        })
      },
      async fixAmoebaSettlementCenterBelongDepart(params){
        this.loadingVerifyDiv2 = true;
        const { code, data, message } = await ajax("fixAmoebaSettlementCenterBelongDepart", params);
        if (code === 200) {
          this.$message.success("操作成功,数量="+data);
        }else{
          if(message){
            this.$message.error(message);
          }else{
            this.$message.error('操作失败');
          }
        }
        this.loadingVerifyDiv2 = false;
      },
      async fixAmoebaSettlementCenterCostDate() {
        this.loadingVerifyDiv = true;
        const { code, data, message } = await ajax("fixAmoebaSettlementCenterCostDate", this.criteriaForm);
        if (code === 200) {
          this.$message.success("操作成功");
        }else{
          if(message){
            this.$message.error(message);
          }else{
            this.$message.error('操作失败');
          }
        }
        this.loadingVerifyDiv = false;
      }
    }
  }
</script>

<style scoped>

</style>
